import json

from django.shortcuts import render_to_response

from Common import sql_content
from DataDisplay.DisplayControl import area as area_class, salary as salary_class, area_map, analysis, demo_mag, \
    undefined_4


# Create your views here.


def showData_school(request):
    mag_Dict = demo_mag._demo_mag().showData_demo()
    return render_to_response('showData_demo.html', {'mag_Dict': mag_Dict})
def showData_society(request):
    mag_Dict = demo_mag._demo_mag().showData_demo()
    return render_to_response('showData_demo.html', {'mag_Dict': mag_Dict})
def showData_all(request):
    mag_Dict = demo_mag._demo_mag().showData_demo()
    print('dataDisplay_1245', mag_Dict)
    return render_to_response('showData_demo.html', {'mag_Dict': mag_Dict})
def showData_policy(request):
    mag_Dict = demo_mag._demo_mag().showData_demo()
    print('dataDisplay_1245',mag_Dict)
    return render_to_response('showData_demo.html', {'mag_Dict': mag_Dict})

def details(request):
    if request.method == "POST":
        # 就业数据，all，1@前10大岗位数量最多的城市
        if request.POST.get('hidDetail')=='1':
            demo = 1
            meg_fill,page = area_class.Job_place().name_main()
        # 就业数据，all，2@部分城市工资情况
        elif request.POST.get('hidDetail')=='2':
            demo = 2
            meg_fill, page = salary_class.Salary_place().name_main()
        elif request.POST.get('hidDetail') == '3':
            demo = 3
            meg_fill, page = area_map.Job_map().name_main()
        elif request.POST.get('hidDetail') == '4':
            demo = 4
            meg_fill, page = undefined_4.Undefined_4().name_main()
            print('views_details_html', meg_fill)
        return render_to_response('showData_details_demo.html', {'demo':demo,'Message': meg_fill, 'page':page})
    return None

def analysis_school(request):
    return render_to_response('analysis_demo.html')
def analysis_society(request):
    return render_to_response('analysis_demo.html')
def analysis_all(request):
    if request.method == "GET":
        data_count = sql_content.sql_content().data_count("select count(*) from data_collection.data_51job_she;")
        page_size = 30
        now_page = 1
        page_begin = 1
        page_end = 30
        end_page_begin = 0
        if (data_count % page_size == 0):
            page_count = data_count / page_size
        else:
            page_count = data_count // page_size + 1
            end_page_begin = data_count // page_size * page_size + 1
            # print(page_count,end_page_begin)
        if(request.GET.get('hidPageIndex') is not None):
            now_page = int(request.GET.get('hidPageIndex'))
            page_end = now_page * page_size
            page_begin = page_end - page_size + 1
            if(page_end > data_count):
                page_end = data_count
        page_count_list = []
        for num in range(1,page_count+1):
            page_count_list.append(num)
        print(page_begin,page_end)
        analysis_fill = analysis._Analysis().analysis_sql(page_begin,page_end)
        page_meg = {'page_count':page_count , 'page_count_list':page_count_list,'now_page':now_page}
        print('views_analysis_fill_modth', analysis_fill)
        return render_to_response('analysis_demo.html', {'Analysis': analysis_fill,'page_meg':page_meg})
    elif request.method == "POST":
        print('this is Post!')
        now_id = int(request.POST.get('hidDetail'))
        if (now_id is not None):
            detail_fill = analysis._Analysis().analysis_sql_id(now_id)
            return render_to_response('analysis_allData_demo.html',{'detail_fill':detail_fill})

    else:
        return render_to_response('analysis_allData_demo.html')